<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 区间内查询数字的频率 -->
    <script>
      var RangeFreqQuery = function (arr) {
        this.list = arr
        this.obj = {}
        RangeFreqQuery.prototype.query = function (left, right, value) {
          if (this.obj[`${left}-${right}-${value}`]) {
            return this.obj[`${left}-${right}-${value}`]
          } else {
            this.obj[`${left}-${right}-${value}`] = this.list.slice(left, right + 1).filter(i => i === value).length
          }
          return this.obj[`${left}-${right}-${value}`]
        }
      }
      let obj = new RangeFreqQuery([12, 33, 4, 56, 22, 2, 34, 33, 22, 12, 34, 56])
      // obj.query(1, 2, 4)// 返回 1 。4 在子数组 [33, 4] 中出现 1 次。
      obj.query(0, 11, 33) // 返回 2 。33 在整个子数组中出现 2 次。
      console.log(RangeFreqQuery(['RangeFreqQuery', 'query', 'query']))
    </script>
  </body>
</html>
